import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/ai-test'
    },
    {
      path: '/home',
      name: 'Home',
      component: () => import('@/views/HomeView.vue'),
      meta: {
        title: '首页',
        requiresAuth: false
      }
    },
    {
      path: '/about',
      name: 'About',
      component: () => import('@/views/AboutView.vue'),
      meta: {
        title: '关于',
        requiresAuth: false
      }
    },
    {
      path: '/ai-test',
      name: 'AiTest',
      component: () => import('@/views/AiChatTestView.vue'),
      meta: {
        title: 'AI聊天测试',
        requiresAuth: false,
        icon: 'Cpu'
      }
    },
    {
      path: '/:pathMatch(.*)*',
      redirect: '/ai-test'
    }
  ]
})

// 路由守卫
router.beforeEach(async (to, from, next) => {
  // 设置页面标题
  if (to.meta?.title) {
    document.title = `${to.meta.title} - AI Agent Platform`
  } else {
    document.title = 'AI Agent Platform'
  }
  
  // 暂时跳过认证检查，直接允许访问
  next()
})

// 路由错误处理
router.onError((error) => {
  console.error('路由错误:', error)
})

export default router